{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <link href="../../static/personnel/css/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        .performance {
            width: 100%;height: 40px;line-height: 40px;padding-left: 10px;border-bottom: #999999 dashed 1px;cursor: pointer;
        }
        .performance_active {
            background: #2db7f5;color: white;border-bottom: #2db7f5 dashed 1px;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 2px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
        .shade {
            position: fixed;top: 0;left: 0;right: 0;bottom: 0;background-color: rgba(36, 36, 36, 0.5);display: none;z-index: 10000;
        }
        .sheet {
            width: 90px;height: 35px;border-top-right-radius: 5px;border-top-left-radius: 5px;border: #cfcfcf solid 1px;font-size: 12px;
        }
        .sheet:hover {
            background: #2db7f5;color: white;border: #2db7f5 solid 1px;
        }
        .sheet_active {
            background: #2db7f5;color: white;border: #2db7f5 solid 1px;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div style="width: 15%;height: 95%;margin-top: 1.25%;display: inline-block;vertical-align: top;background: white;border: #cfcfcf solid 1px;margin-left: 1%;">
        <div onclick="window.location.href='/supervision-inspection/performance_management.html'" class="performance performance_active">
            绩效分配
        </div>
        <div onclick="window.location.href='/supervision-inspection/supervise_completed.html'" class="performance">
            绩效汇总
        </div>
        <div onclick="window.location.href='/supervision-inspection/department_performance.html'" class="performance" {% if share_flag == 'true' %}style="color: red;"{% endif %} >
            科室绩效
        </div>
        <div onclick="choose_performance_type(this, 4)" class="performance">
            我的绩效
        </div>
    </div>

    <div style="width: 82%;height: 95%;margin-top: 1.25%;display: inline-block;vertical-align: top;background: white;border: #cfcfcf solid 1px;margin-left: 0.5%;">
        <div style="width: 100%;height: 100%;" id="performance_allocation">
            {% if upload_flag == 'true' %}
                <div style="width: 100%;height: 40px;border-bottom: #cfcfcf solid 1px;">
                    <div style="float: left;height: 40px;border-bottom: #cfcfcf solid 1px;padding-left: 10px;padding-right: 10px;">
                        <button style="width: 100px;height: 30px;border: #2db7f5 solid 1px;background: #2db7f5;border-radius: 3px;margin-top: 5px;color: white;" onclick="upload_performance(1)">上传绩效</button>
                        <button style="width: 100px;height: 30px;border: #00A680 solid 1px;background: #00A680;border-radius: 3px;margin-top: 5px;color: white;margin-left: 10px;" onclick="location.href=('../../static/supervision_inspection/file_model/绩效汇总表.xlsx')">下载模板</button>
                    </div>

                    <div style="float: right;margin-right: 15px;display: inline-block;vertical-align: top;">
                        <div style="display: inline-block;vertical-align: top;width: 200px;height: 40px;padding-top: 5px;">
                            <select name="" id="month" style="width: 100%;height: 30px;border: #cfcfcf solid 1px;border-radius: 3px;outline: none;" class="dept_select">
                                <option value="0">请选择年份</option>
                                {% for year in year_list %}
                                    <option value="{{ year }}">{{ year }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div style="display: inline-block;vertical-align: top;width: 200px;height: 40px;padding-top: 5px;">
                            <select name="dept" style="width: 100%;height: 30px;border: #cfcfcf solid 1px;border-radius: 3px;outline: none;" id="dept" class="dept_select">
                                <option value="0">请选择月份</option>
                                {% for month in month_list %}
                                    <option value="{{ month }}">{{ month }}</option>
                                {% endfor %}
                            </select>
                        </div>

    {#                    <input type="text" style="width: 300px;height: 30px;margin-top: 5px;border: #2db7f5 solid 1px;border-top-left-radius: 3px;border-bottom-left-radius: 3px;margin-right: -4.5px;">#}
                        <button style="width: 100px;height: 30px;margin-top: 5px;letter-spacing: 5px;background: #2db7f5;border: #2db7f5 solid 1px;color: white;">搜索</button>
                    </div>
                </div>
                <div id="table_detail" style="width: 100%;height: 91%;overflow-x: auto;">
                    <table id="main_table" style="width: 1950px;">
                        <tr style="border-bottom: #cfcfcf solid 1px;">
                            <td colspan="16" style="width: 1850px;height: 40px;line-height: 40px;text-align: center;"><strong style="font-size: 18px;">{{ search_year }}年{{ search_month }}月绩效工资分配表</strong></td>
                            <td style="width: 100px;height: 40px;line-height: 40px;text-align: center;border-left: #cfcfcf solid 1px;"><strong style="font-size: 18px;">正01表</strong></td>
                        </tr>
                        <tr style="border-bottom: #cfcfcf solid 1px;">
                            <td colspan="17" style="width: 1950px;height: 30px;line-height: 30px;text-align: left;padding-left: 15px;font-size: 12px;">单位：协和京山医院</td>
                        </tr>
                        <tr style="border-bottom: #cfcfcf solid 1px;">
                            <td rowspan="2" style="width: 200px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">科室</td>
                            <td rowspan="2" style="width: 200px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">科室编号</td>
                            <td rowspan="2" style="width: 100px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">科室负责人</td>
                            <td rowspan="2" style="width: 100px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">工号</td>
                            <td colspan="2" style="width: 200px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;font-size: 12px;">科室绩效</td>
                            <td rowspan="2" style="width: 100px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">科室绩效合计</td>
                            <td rowspan="2" style="width: 100px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">科主任科室绩效</td>
                            <td colspan="7" style="width: 750px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;font-size: 12px;">专项绩效</td>
                            <td rowspan="2" style="width: 100px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">专项绩效合计</td>
                            <td rowspan="2" style="width: 100px;height: 60px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 60px;font-size: 12px;">应发绩效总计</td>
                        </tr>
                        <tr style="border-bottom: #cfcfcf solid 1px;">
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">工作量绩效</td>
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">综合考核绩效</td>
                            <td style="width: 150px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">科主任管理绩效</td>
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">夜班绩效</td>
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">会诊绩效</td>
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">门诊专项绩效</td>
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">医共体绩效</td>
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">其他单项绩效</td>
                            <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">人才储备绩效</td>
                        </tr>
                        {% for items in obj %}
                            <tr style="border-bottom: #cfcfcf solid 1px;">
                                <td style="width: 200px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.department_name }}</td>
                                <td style="width: 200px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.department_code }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.department_director }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.job_number }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.workload }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.synthesize }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.department_total }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.director_performance }}</td>
                                <td style="width: 150px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.director_control_performance }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.night_shift_performance }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.consultation_performance }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.outpatient_special_performance }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.medical_community }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.other_single }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.talent_reserve }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.special_performance }}</td>
                                <td style="width: 100px;height: 30px;text-align: center;border-right: #cfcfcf solid 1px;line-height: 30px;">{{ items.expected_performance }}</td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
                <div style="width: 100%;height: 40px;padding-left: 5px;overflow-y: auto;">
                    <button onclick="choose_sheet(this, 'a')" class="sheet sheet_active">绩效主表</button>
                    <button onclick="choose_sheet(this, 'b')" class="sheet">临床科室</button>
                    <button onclick="choose_sheet(this, 'c')" class="sheet">人才储备绩效</button>
                    <button onclick="choose_sheet(this, 'd')" class="sheet">其他单项</button>
                    <button onclick="choose_sheet(this, 'e')" class="sheet">医共体专项</button>
                    <button onclick="choose_sheet(this, 'f')" class="sheet">门诊专项绩效</button>
                    <button onclick="choose_sheet(this, 'g')" class="sheet">会诊绩效</button>
                    <button onclick="choose_sheet(this, 'h')" class="sheet">夜班绩效</button>
                    <button onclick="choose_sheet(this, 'i')" class="sheet" style="width: 120px;">科主任管理绩效 </button>
                    <button onclick="choose_sheet(this, 'j')" class="sheet" style="width: 140px;">综合目标绩效(临床)</button>
                    <button onclick="choose_sheet(this, 'k')" class="sheet" style="width: 140px;">综合目标绩效(医技)</button>
                    <button onclick="choose_sheet(this, 'l')" class="sheet" style="width: 140px;">新入职人才储备绩效</button>
                </div>
            {% else %}
                <div style="width: 100%;height: 100%;">
                    <div style="width: 30%;height: 30%;margin-top: 18%;margin-left: 30%;text-align: center;">
                <img src="../../static/personal_center/img/暂无资源.png" alt="" style="width: 120px;height: 120px;margin-top: 30px;">
                <p style="color: #cfcfcf;">无权限访问</p>
            </div>
                </div>
            {% endif %}
        </div>

        <div style="width: 100%;height: 100%;overflow: auto;display: none;" id="performance_statistics"></div>
        <div style="width: 100%;height: 100%;overflow: auto;display: none;" id="department_performance">

        </div>
        <div style="width: 100%;height: 100%;overflow: auto;display: none;" id="my_performance">
            <div style="width: 30%;height: 30%;margin-top: 18%;margin-left: 30%;text-align: center;">
                <img src="../../static/personal_center/img/暂无资源.png" alt="" style="width: 120px;height: 120px;margin-top: 30px;">
                <p style="color: #cfcfcf;">该功能暂未开放</p>
            </div>
        </div>
    </div>

    <div id="upload_meeting_minutes" class="shade">
        <div id="meeting_minutes" style="width: 100%;height: 100%;position: absolute;">
            <div style="width: 400px;background: #F5F5F5;z-index: 10000;position: absolute;top: 50%;left: 50%;transform:translate(-50%,-50%);border-radius: 3px;border: #dfdfdf solid 1px;">
                <div id="minutes" style="width: 400px;height: 40px;background: #f4f7fa;cursor: move;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom: #cfcfcf solid 1px;">
                    <h6 class="modal-title" style="line-height: 40px;width: 35%;margin-left: 1%;display: inline-block;">上传绩效</h6>
                    <span onclick="close_models()" style="float: right;line-height: 40px;padding-right: 2%;cursor: pointer;"><i class="iconfont icon-quchu"></i></span>
                </div>

                <div style="width: 400px;border-bottom: #cfcfcf solid 1px;padding-bottom: 20px;">
                    <div style="padding-left: 15px;margin-top: 15px;">
                        <label for="">绩效年份：</label>
                        <input type="text" id="performance_year" style="width: 250px;height: 30px;border: #cfcfcf solid 1px;outline: none;border-radius: 3px;">
                    </div>

                    <div style="padding-left: 15px;margin-top: 15px;">
                        <label for="">绩效月份：</label>
                        <input type="text" id="performance_month" style="width: 250px;height: 30px;border: #cfcfcf solid 1px;outline: none;border-radius: 3px;">
                    </div>

                    <div style="padding-left: 15px;margin-top: 30px;">
                        <label for="">上传绩效：</label>
                        <div style="margin-left: 2%;width: 70%;height: 40px;display: inline-block;">
                            <div style="width: 40px;height: 40px;display: inline-block;vertical-align: top;">
                                <a href="javascript:;" class="file">
                                    <img src="../../static/personal_center/img/加号_o.png" alt="" onclick="onclick_upload_file()" style="width: 30px;height: 40px;vertical-align: baseline;">
                                    <input type="file" name="regular_main_body" id="regular_main_body" onchange="upload_accessory()">
                                </a>
                            </div>

                            <div id="upload_file_list" style="width: 76%;height: 100%;display: inline-block;vertical-align: top;margin-left: 19px;">

                            </div>
                        </div>
                    </div>
                </div>

                <div style="width: 400px;height: 40px;text-align: right;padding-right: 2%;">
                    <button id="SubmitSummary" style="width: 100px;height: 30px;border: #dfdfdf solid 1px;border-radius: 3px;background: #1E90FF;color: white;margin-top: 5px;">
                        提交
                    </button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script src="../../static/personnel/js/jquery-1.11.1.min.js"></script>
    <script src="../../static/personnel/js/jquery.searchableSelect.js"></script>
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("personage").className = "add_class";
            document.getElementById("supervision_inspection_management").className = "add-nav-active";
        };

        function choose_performance_type(ele, type_number) {
            var performance_obj = document.getElementsByClassName("performance");
            for (var i=0; i<performance_obj.length; i++) {
                performance_obj[i].className = "performance";
            }
            ele.className = "performance performance_active";

            if (type_number === 1) {
                document.getElementById("performance_allocation").style.display = "block";
                document.getElementById("performance_statistics").style.display = "none";
                document.getElementById("department_performance").style.display = "none";
                document.getElementById("my_performance").style.display = "none";
            }else if (type_number === 2) {
                document.getElementById("performance_statistics").style.display = "block";
                document.getElementById("performance_allocation").style.display = "none";
                document.getElementById("department_performance").style.display = "none";
                document.getElementById("my_performance").style.display = "none";
            }else if (type_number === 3) {
                document.getElementById("department_performance").style.display = "block";
                document.getElementById("performance_allocation").style.display = "none";
                document.getElementById("performance_statistics").style.display = "none";
                document.getElementById("my_performance").style.display = "none";
            }else {
                document.getElementById("my_performance").style.display = "block";
                document.getElementById("performance_allocation").style.display = "none";
                document.getElementById("performance_statistics").style.display = "none";
                document.getElementById("department_performance").style.display = "none";
            }
        }

        let minutes = document.querySelector("#minutes");
        let meeting_minutes = document.querySelector("#meeting_minutes");

        minutes.addEventListener("mousedown", function (e) {
            let x = e.pageX - meeting_minutes.offsetLeft;
            let y = e.pageY - meeting_minutes.offsetTop;

            document.addEventListener("mousemove", move);
            function move(e) {
                meeting_minutes.style.left = e.pageX - x + 'px';
                meeting_minutes.style.top = e.pageY - y + 'px';
            }

            document.addEventListener("mouseup", function (e) {
                document.removeEventListener("mousemove", move);
            })
        });

        function upload_performance(upload_type) {
            document.getElementById("upload_meeting_minutes").style.display = "table-row";
            document.getElementById("SubmitSummary").setAttribute("onclick", "submit_summary('"+upload_type+"')")
        }

        function close_models() {
            document.getElementById("upload_meeting_minutes").style.display = "none";
        }

        function onclick_upload_file() {
            document.getElementById("regular_main_body").click();
        }

        function upload_accessory() {
            var form = new FormData();
            var files = document.getElementById("regular_main_body").files[0];
            creat_table(files.name)
        }

        function creat_table(file_name) {
            var html_str = `
                <div style="width: 100%;height: 40px;line-height: 40px;">
                    <div style="width: 79%;height: 100%;display: inline-block;vertical-align: top;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
                        <a target='_blank' href="javascript:;">`+file_name+`</a>
                    </div>
                    <div onclick="RemoveTr(this)" style="width: 18%;height: 100%;display: inline-block;vertical-align: top;text-align: center;font-size: 12px;cursor: pointer;color: red;">
                        删除
                    </div>
                </div>
            `
            $("#upload_file_list").append(html_str)
        }

        function RemoveTr(_this) {
            var parentNode = _this.parentNode;
            parentNode.remove()
        }

        function submit_summary(upload_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById("regular_main_body").files;
            var performance_year = document.getElementById("performance_year").value;
            var performance_month = document.getElementById("performance_month").value;
            if (!performance_month) {
                alert("请输入绩效月份！")
                return false
            }
            if (!performance_year) {
                alert("请输入绩效年份！")
                return false
            }
            if (!files.length) {
                alert("请上传绩效！")
                return false
            }
            form.append("file", files[0]);
            form.append("upload_type", upload_type);
            form.append("performance_year", performance_year);
            form.append("performance_month", performance_month);
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/supervision-inspection/department_uploads_performance", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        window.location.reload();
                    }
                }
             };
        }

        function choose_sheet(eve_this, data_type) {
            var sheet_list = document.getElementsByClassName("sheet");
            for (var i=0; i<sheet_list.length; i++) {
                sheet_list[i].className = "sheet"
            }
            eve_this.className = "sheet sheet_active";
            switch_tables(data_type);
        }

        $(function(){
            $('select').searchableSelect();
        });
        
        function switch_tables(data_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            form.append("search_year", '{{ search_year }}');
            form.append("search_month", '{{ search_month }}');
            form.append("data_type", data_type);
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/supervision-inspection/SwitchTables", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        if (JsonDate['code'] === 200) {
                            document.getElementById("main_table").innerHTML = "";
                            $("#main_table").append(JsonDate['data'])
                        }else {
                            alert(JsonDate['message'])
                        }
                    }
                }
             };
        }
    </script>
{% endblock %}
